/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#pragma once

#include <vector>
using namespace std;

struct Position {
	short x;
	short y;
	bool operator ==(const int& n) const{
		return x == n && y == n;
	}
	bool operator !=(const int& n) const{
		return !(*this==n);
	}
	Position (short x,short y)
	{
		this->x = x;
		this->y = y;
	}
	Position()
	{
		this->x = 0;
		this->y = 0;
	}
};

class Value {
	__int64 type;
	int value;
public:
	Value(__int64 type, int value){
		this->type = type;
		this->value = value;
	}
	__int64 getType(){
		return type;
	}
	int getValue(){
		return value;
	}
};

class Values {
protected:
	int pos;
	vector <Value> values;
public:
	Values(){
		pos = -1;
	}
	void add(Value value){
		values.push_back(value);
	}
	void sort();
	vector <Value>* getValues(){
		return &values;
	}
	int getSize(){
		return (int)values.size();
	}
	int getValueByType(__int64 type){
		for(int i=0; i<(int)values.size(); i++){
			if(values[i].getType() == type)
				return values[i].getValue();
		}
		return 0;

	}
	bool contain(__int64 type){
		for(int i = 0; i < (int)values.size(); i++){
			if(values[i].getType() == type)
				return true;
		}
		return false;
	}
};

struct IP {
	unsigned char p1;
	unsigned char p2;
	unsigned char p3;
	unsigned char p4;
	void operator = (const IP& ip) {
		p1 = ip.p1;
		p2 = ip.p2;
		p3 = ip.p3;
		p4 = ip.p4;
	}
	bool operator == (const IP& ip) {
		return p1 == ip.p1 && p2 == ip.p2 && p3 == ip.p3 && p4 == ip.p4;
	}
	bool operator != (const IP& ip) {
		return !(*this == ip);
	}
};

struct Time {
	unsigned char hour;
	unsigned char minute;
	unsigned char second;
};

namespace Tools {
	int getDistance(Position& pos1, Position& pos2);
	void randomize();
	int randomInt();
	int getivRecv();
	int getivSend();
	int random(int min, int max);
	int random(int n);
	Time getTime();
	int getServerTime();
	int getTimeUntilNextMinute();
	int getMinute();
	__int64 getLongTime();
	__int64 doubleAsLong(double num);
	__int64 getStatsType(Values* values);
	__int64 getTimeByDays(int days);
	IP stringToIP(string& ip);
	string intToString(int num);
	bool isFirstBuff(__int64 effect);
};
